﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace=" System.Collections" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="TarreOA.TarreOAModels" %>
<%@ Import Namespace="TarreOA.TarreOABLL" %>

<script runat="server">

    private int curYear;
    private int curMonth;
    protected void Page_Load(object sender, EventArgs e) {
        if(!Page.IsPostBack) {
            curYear = DateTime.Now.Year;
            curMonth = DateTime.Now.Month;
            for(int i = 1958; i < 2058; i++) {
                ListItem item = new ListItem(i.ToString(), i.ToString());
                if(i == curYear) {
                    item.Selected = true;
                }
                this.DdlYear.Items.Add(item);
            }
            for(int i = 1; i < 13; i++) {
                ListItem item = new ListItem(i.ToString(), i.ToString());
                if(i == curMonth) {
                    item.Selected = true;
                }
                this.DdlMonth.Items.Add(item);
            }
            AddDateText();
            this.addCurLoginUserCalendarInfo();
            ViewState["curYear"] = curYear;
            ViewState["curMonth"] = curMonth;
        }
        string c_dt = DateTime.Now.ToShortDateString().Replace("-", "/");
        this.HyperLink2.NavigateUrl = "CalendarArrangeShow.aspx?c_dt=" + c_dt;
    }

    private void AddDateText() {
        User curLoginUser = (User) Session["user"];
        for(int i = 1; i < 43; i++) {
            ((Label) this.FindControl("Label" + i)).Text = "";
        }
        DateTime dt;
        int d;
        if(curMonth < 1) {
            curYear--;
            curMonth = 12;
            dt = DateTime.Parse(curYear + "-" + (curMonth - 1) + "-" + DateTime.DaysInMonth(curYear, curMonth - 1));

        } else if(curMonth == 1) {
            dt = DateTime.Parse((curYear - 1) + "-" + 12 + "-" + DateTime.DaysInMonth((curYear - 1), 12));
        } else if(curMonth > 12) {
            dt = DateTime.Parse(curYear + "-" + 12 + "-" + DateTime.DaysInMonth(curYear, 12));
            curYear++;
            curMonth = 1;
        } else {
            dt = DateTime.Parse(curYear + "-" + (curMonth - 1) + "-" + DateTime.DaysInMonth(curYear, curMonth - 1));
        }
        d = DateTime.DaysInMonth(curYear, curMonth);
        int start = 1;
        if(dt.AddDays(1).DayOfWeek == DayOfWeek.Monday) {
            start = 2;
        } else if(dt.AddDays(1).DayOfWeek == DayOfWeek.Tuesday) {
            start = 3;
        } else if(dt.AddDays(1).DayOfWeek == DayOfWeek.Wednesday) {
            start = 4;
        } else if(dt.AddDays(1).DayOfWeek == DayOfWeek.Thursday) {
            start = 5;
        } else if(dt.AddDays(1).DayOfWeek == DayOfWeek.Friday) {
            start = 6;
        } else if(dt.AddDays(1).DayOfWeek == DayOfWeek.Saturday) {
            start = 7;
        }
        for(int i = 1; i <= d; i++) {
            DateTime ddt = DateTime.Parse(curYear + "-" + curMonth + "-" + i.ToString());
            UserCalendarArrangetbService ucatbService = new UserCalendarArrangetbService();
            List<UserCalendarArrangetb> list = ucatbService.findCurDateAllByUserLoginNameAndCurDate(curLoginUser.LoginName, ddt);
            string caCount = "";
            if(list != null && list.Count > 0) {
                caCount = "<br/><font style='font-size:12px'>今日有<font color='red'><b>" + list.Count.ToString() + "</b></font>个事务</font>";
            }
            if(i == DateTime.Now.Day && curYear == DateTime.Now.Year && curMonth == DateTime.Now.Month) {
                ((Label) this.FindControl("Label" + start)).Text = "<a style='text-decoration: none' href='CalendarArrangeShow.aspx?c_dt=" +
                    curYear + "/" + curMonth + "/" + i.ToString() + "'><font style='font-size:20px'><b>" + i.ToString() + "</b></font></a>" + caCount;
            } else if(ddt.DayOfWeek == DayOfWeek.Saturday || ddt.DayOfWeek == DayOfWeek.Sunday) {
                ((Label) this.FindControl("Label" + start)).Text = "<a style='text-decoration: none' href='CalendarArrangeShow.aspx?c_dt=" +
                    curYear + "/" + curMonth + "/" + i.ToString() + "'><font color='red'><b>" + i.ToString() + "</b></font></a>" + caCount;
            } else {
                ((Label) this.FindControl("Label" + start)).Text = "<a style='text-decoration: none' href='CalendarArrangeShow.aspx?c_dt=" + curYear + "/" + curMonth +
                    "/" + i.ToString() + "'>" + i.ToString() + "</a>" + caCount;
            }
            start++;
        }
        //DateTime.Now.Month == curMonth ? this.Label43.Text = "<font color='yellow'>" + curMonth.ToString() + "</font>月" :
        //    this.Label43.Text = curMonth.ToString() + "月";
        //curYear == DateTime.Now.Year ? this.Label44.Text = "<font color='yellow'>" + curYear.ToString() + "</font>年" : 
        //    this.Label44.Text = curYear.ToString() + "年";
        if(curMonth == DateTime.Now.Month && curYear == DateTime.Now.Year) {
            this.Label43.Text = "<font color='#777777'>" + curMonth.ToString() + "月</font>";
            this.Label44.Text = "<font color='#777777'>" + curYear.ToString() + "年</font>";
        } else {
            this.Label43.Text = curMonth.ToString() + "月";
            this.Label44.Text = curYear.ToString() + "年";
        }
    }


    protected void Button1_Click(object sender, EventArgs e) {
        if(ViewState["curMonth"] != null && ViewState["curYear"] != null) {
            curMonth = (int) ViewState["curMonth"];
            curYear = (int) ViewState["curYear"];
        }
        curMonth--;
        AddDateText();
        ViewState["curMonth"] = curMonth;
        ViewState["curYear"] = curYear;
    }

    protected void Button2_Click(object sender, EventArgs e) {
        if(ViewState["curMonth"] != null && ViewState["curYear"] != null) {
            curMonth = (int) ViewState["curMonth"];
            curYear = (int) ViewState["curYear"];
        }
        curMonth++;
        AddDateText();
        ViewState["curMonth"] = curMonth;
        ViewState["curYear"] = curYear;
    }

    protected void Button3_Click(object sender, EventArgs e) {
        if(ViewState["curYear"] != null && ViewState["curMonth"] != null) {
            curMonth = (int) ViewState["curMonth"];
            curYear = (int) ViewState["curYear"];
        }
        curYear--;
        AddDateText();
        ViewState["curYear"] = curYear;
        ViewState["curMonth"] = curMonth;
    }

    protected void Button4_Click(object sender, EventArgs e) {
        if(ViewState["curYear"] != null && ViewState["curMonth"] != null) {
            curMonth = (int) ViewState["curMonth"];
            curYear = (int) ViewState["curYear"];
        }
        curYear++;
        AddDateText();
        ViewState["curYear"] = curYear;
        ViewState["curMonth"] = curMonth;
    }

    protected void DdlYear_SelectedIndexChanged(object sender, EventArgs e) {
        if(ViewState["curMonth"] != null && ViewState["curYear"] != null) {
            curYear = (int) ViewState["curYear"];
            curMonth = (int) ViewState["curMonth"];
        }
        curYear = int.Parse(Request.Params.GetValues(this.DdlYear.ClientID)[0]);
        curMonth = int.Parse(Request.Params.GetValues(this.DdlMonth.ClientID)[0]);
        AddDateText();
        ViewState["curYear"] = curYear;
        ViewState["curMonth"] = curMonth;
    }

    protected void DdlMonth_SelectedIndexChanged(object sender, EventArgs e) {
        if(ViewState["curMonth"] != null && ViewState["curYear"] != null) {
            curYear = (int) ViewState["curYear"];
            curMonth = (int) ViewState["curMonth"];
        }
        curYear = int.Parse(Request.Params.GetValues(this.DdlYear.ClientID)[0]);
        curMonth = int.Parse(Request.Params.GetValues(this.DdlMonth.ClientID)[0]);
        AddDateText();
        ViewState["curYear"] = curYear;
        ViewState["curMonth"] = curMonth;
    }

    protected void Timer1_Tick(object sender, EventArgs e) {
        User curLoginUser = (User) Session["user"];
        CalendarArrangeInfos caInfos = CalendarArrangeInfos.instance();
        if(caInfos.Cainfos[curLoginUser.LoginName] == null) {
            this.addCurLoginUserCalendarInfo();
        } else {
            List<UserCalendarArrangetb> list = (List<UserCalendarArrangetb>) caInfos.Cainfos[curLoginUser.LoginName];
            if(list.Count > 0) {
                string script = "";
                foreach(UserCalendarArrangetb ucatb in list) {
                    DateTime startTime = DateTime.Parse(ucatb.CalendarArrangeDate.ToShortDateString() + " " + ucatb.CalendarArrangeStartTime);
                    DateTime endTime = DateTime.Parse(ucatb.CalendarArrangeDate.ToShortDateString() + " " + ucatb.CalendarArrangeEndTime);
                    if(startTime <= DateTime.Now && endTime >= DateTime.Now) {
                        TimeSpan minutes = DateTime.Now - startTime;
                        if(minutes.Minutes % ucatb.CalendarArrangeIntervalMinute == 0) {
                            //ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "window.open('ShowModel.aspx?ca_id=" 
                            //    + ucatb.CalendarArrangeId + "', '', 'status:no;center:yes;scroll:0;resizable:no;help:no;dialogWidth:570px;dialogHeight:445px');", true);
                            script += "window.open('ShowModel.aspx?ca_id=" + ucatb.CalendarArrangeId + "');";
                        }
                    }
                }
                if(!"".Equals(script)) {
                    ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", script, true);
                }
            }
        }
    }

    private void addCurLoginUserCalendarInfo() {
        DateTime curDt = DateTime.Parse(DateTime.Now.ToShortDateString());
        User curLoginUser = (User) Session["user"];
        CalendarArrangeInfos caInfos = CalendarArrangeInfos.instance();
        UserCalendarArrangetbService ucatbService = new UserCalendarArrangetbService();
        List<UserCalendarArrangetb> list = ucatbService.findCurDateAllByUserLoginNameAndCurDate(curLoginUser.LoginName, curDt);
        if(list == null) {
            list = new List<UserCalendarArrangetb>();
        }
        if(caInfos.Cainfos[curLoginUser.LoginName] == null) {
            caInfos.AddCaInfos(curLoginUser.LoginName, list);
        } else {
            List<UserCalendarArrangetb> lists = (List<UserCalendarArrangetb>) caInfos.Cainfos[curLoginUser.LoginName];
            if(lists.Count > 0) {
                if(lists[0].CalendarArrangeDate.Date != curDt) {
                    caInfos.Cainfos.Remove(curLoginUser.LoginName);
                    caInfos.AddCaInfos(curLoginUser.LoginName, list);
                }
            }
        }
    }
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>

   <link rel="Stylesheet" type="text/css" href="../Styles/right_style.css" />
   <script type="text/javascript" src="../Scripts/jquery.ui/js/jquery.js"></script>

   <style type="text/css">
<!--
html{ scrollbar-base-color: #dbecf8; scrollbar-arrow-color: #2a8ed1; scrollbar-track-color: #bdddf2; scrollbar-3dlight-color: #2886c5; scrollbar-darkshadow-color: #2886c5;
scrollbar-face-color: #dbecf8; scrollbar-shadow-color: #dbecf8;  }
-->
</style>


</head>
<body>
    <form id="form1" runat="server">
        <div  class="sub_right_top">
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>

            <!--滑动门-->
    <div class="hdm_header" >
     <div class="tb1_on" id="tab1" onclick="changeTag(this.id)"><h2 class="h2_icon">
     <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/CalendarArrange/ArrangeIndex.aspx">日程安排</asp:HyperLink>
     </h2></div>
     <div class="tb1_off" id="tab2" onclick="changeTag(this.id)"><h2 class="h2_icon">
      <asp:HyperLink ID="HyperLink2" runat="server">今日日程</asp:HyperLink>
     </h2></div>
      <div class="tb1_off" id="tab3" onclick="changeTag(this.id)"><h2 class="h2_icon">
            <asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="~/CalendarArrange/CalendarArrangeDemand.aspx">日程查询</asp:HyperLink>
      </h2></div>
     <div class="clear"></div>
   </div>
    <div class="hdm_footer">
        <div id="tb1_1_content" class="cont01_word"  style="display:block;">
        <div style="height:13px;"></div>   
           <table class="schedule_clmonth" width="97%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#77acd0" style="border-collapse:collapse; text-align: center;">
                            <tr>
                                <th  colspan="7" align="center">
                                    查看
                                    <asp:DropDownList ID="DdlYear" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DdlYear_SelectedIndexChanged" ></asp:DropDownList>
                                    年
                                    <asp:DropDownList ID="DdlMonth" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DdlMonth_SelectedIndexChanged" ></asp:DropDownList>
                                     月
                                    <asp:ImageButton ID="Button1" runat="server" OnClick="Button1_Click"  ImageUrl="~/images/rc_left.png" CssClass="rc_icon" />
                                    <asp:Label ID="Label43" runat="server" Width="54px" Font-Bold="True"></asp:Label>
                                    <asp:ImageButton ID="Button2" runat="server" OnClick="Button2_Click"  ImageUrl="~/images/rc_right.png"  CssClass="rc_icon" />

                                    <asp:ImageButton ID="Button3" runat="server" OnClick="Button3_Click"  ImageUrl="~/images/rc_left.png" CssClass="rc_icon"  />
                                     <asp:Label ID="Label44" runat="server" Width="65px" Font-Bold="True"></asp:Label>
                                     <asp:ImageButton ID="Button4" runat="server" OnClick="Button4_Click"  ImageUrl="~/images/rc_right.png" CssClass="rc_icon"  />
                                      </th>
                            </tr>
                            <tr>
                                <td class="schedule_color">日</td>
                                <td>一</td>
                                <td>二</td>
                                <td>三</td>
                                <td>四</td>
                                <td>五</td>
                                <td class="schedule_color">六</td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:Label ID="Label1" runat="server" Text=" " ></asp:Label></td>
                                <td><asp:Label ID="Label2" runat="server" Text=" "></asp:Label></td>
                                <td><asp:Label ID="Label3" runat="server" Text=" "></asp:Label></td>
                                <td><asp:Label ID="Label4" runat="server" Text=" "></asp:Label></td>
                                <td><asp:Label ID="Label5" runat="server" Text=" "></asp:Label></td>
                                <td><asp:Label ID="Label6" runat="server"  Text=" "></asp:Label></td>
                                <td><asp:Label ID="Label7" runat="server"  Text=" "></asp:Label></td>
                            </tr>
                            <tr height="40" style="background-color: #FFFFFF">
                                <td align="center" style="width: 98px; height: 40px;">
                                    &nbsp;<asp:Label ID="Label8" runat="server"  Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px; height: 40px;">
                                    &nbsp;<asp:Label ID="Label9" runat="server"  Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px; height: 40px;">
                                    &nbsp;<asp:Label ID="Label10" runat="server"  Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px; height: 40px;">
                                    &nbsp;<asp:Label ID="Label11" runat="server"  Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px; height: 40px;">
                                    &nbsp;<asp:Label ID="Label12" runat="server"  Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px; height: 40px;">
                                    &nbsp;<asp:Label ID="Label13" runat="server" Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px; height: 40px;">
                                    &nbsp;<asp:Label ID="Label14" runat="server" Text=" "></asp:Label></td>
                            </tr>
                            <tr height="40" style="background-color: #FFFFFF">
                                <td align="center" style="width: 98px">
                                    &nbsp;<asp:Label ID="Label15" runat="server"  Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px">
                                    &nbsp;<asp:Label ID="Label16" runat="server"  Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px">
                                    &nbsp;<asp:Label ID="Label17" runat="server"  Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px">
                                    &nbsp;<asp:Label ID="Label18" runat="server"  Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px">
                                    &nbsp;<asp:Label ID="Label19" runat="server"  Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px">
                                    &nbsp;<asp:Label ID="Label20" runat="server"  Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px">
                                    &nbsp;<asp:Label ID="Label21" runat="server" Text=" "></asp:Label></td>
                            </tr>
                            <tr height="40" style="background-color: #FFFFFF">
                                <td align="center" style="width: 98px">
                                    &nbsp;<asp:Label ID="Label22" runat="server"  Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px">
                                    &nbsp;<asp:Label ID="Label23" runat="server"  Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px">
                                    &nbsp;<asp:Label ID="Label24" runat="server" Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px">
                                    &nbsp;<asp:Label ID="Label25" runat="server" Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px">
                                    &nbsp;<asp:Label ID="Label26" runat="server"  Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px">
                                    &nbsp;<asp:Label ID="Label27" runat="server"  Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px">
                                    &nbsp;<asp:Label ID="Label28" runat="server" Text=" "></asp:Label></td>
                            </tr>
                            <tr height="40" style="background-color: #FFFFFF">
                                <td align="center" style="width: 98px">
                                    &nbsp;<asp:Label ID="Label29" runat="server"  Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px">
                                    &nbsp;<asp:Label ID="Label30" runat="server" Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px">
                                    &nbsp;<asp:Label ID="Label31" runat="server"  Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px">
                                    &nbsp;<asp:Label ID="Label32" runat="server" Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px">
                                    &nbsp;<asp:Label ID="Label33" runat="server"  Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px">
                                    &nbsp;<asp:Label ID="Label34" runat="server"  Text=" "></asp:Label></td>
                                <td align="center" style="width: 98px">
                                    &nbsp;<asp:Label ID="Label35" runat="server" Text=" "></asp:Label></td>
                            </tr>
                            <tr height="40" style="background-color: #FFFFFF">
                                <td align="center" style="height: 40px; width: 98px;">
                                    &nbsp;<asp:Label ID="Label36" runat="server" Text=" "></asp:Label></td>
                                <td style="height: 40px; width: 98px;">
                                    &nbsp;<asp:Label ID="Label37" runat="server"  Text=" "></asp:Label></td>
                                <td style="height: 40px; width: 98px;">
                                    &nbsp;<asp:Label ID="Label38" runat="server"  Text=" "></asp:Label></td>
                                <td style="height: 40px; width: 98px;">
                                    &nbsp;<asp:Label ID="Label39" runat="server" Text=" "></asp:Label></td>
                                <td style="height: 40px; width: 98px;">
                                    <asp:Label ID="Label40" runat="server" Text=" "></asp:Label>&nbsp;</td>
                                <td style="height: 40px; width: 98px;">
                                    &nbsp;<asp:Label ID="Label41" runat="server"  Text=" "></asp:Label></td>
                                <td style="height: 40px; width: 98px;">
                                    <asp:Label ID="Label42" runat="server" Text=" "></asp:Label>&nbsp;</td>
                            </tr>
                        </table>
                </div>
            </div>
        </div>
    </form>
</body>
</html>
